package com.chocho.producerserver.controller;

import com.chocho.producerserver.service.PaperService;
import com.chocho.producerserver.utils.Msg;
import com.chocho.producerserver.vo.VCollection;
import com.chocho.producerserver.vo.VPaper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created by chocho on 2022/4/12.
 */
@CrossOrigin
@RestController
@RequestMapping("/paper")
public class PaperController {
    private Logger logger = LoggerFactory.getLogger(PaperController.class);

    @Autowired
    private PaperService paperService;

    //根据题目id获取结果
    @PostMapping("/select")
    @ResponseBody
    public Msg selectPaper(@RequestBody Map<String, Object> map){
        List<VPaper> paperList = paperService.getPaperByQuery(map);
        return (paperList != null)
                ? Msg.success().add("paperList", paperList)
                : Msg.fail();
    }

    //根据用户id，题目id获取结果
    @PostMapping("/select/by/uid")
    @ResponseBody
    public Msg selectPaperByID(HttpServletRequest request, @RequestBody Map<String, Object> map){
        List<VPaper> paperList = paperService.getPaperById(request, map);
        return (paperList != null)
                ? Msg.success().add("paperList", paperList)
                : Msg.fail();
    }
}
